package com.packer.walle;

import java.util.Objects;

final class Pair<A,B> {

    private final A mFirst;
    private final B mSecond;

    private Pair(A first,B second) {
        mFirst = first;
        mSecond = second;
    }

    public static <A,B> Pair<A, B> of(A first,B second) {
        return new Pair<>(first,second);
    }

    public A getFirst() {
        return mFirst;
    }

    public B getSecond() {
        return mSecond;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o != null && getClass() == o.getClass()) {
            Pair<A, B> pair = (Pair) o;
            if (mFirst == null) {
                if (pair.mFirst == null) {
                    return Objects.equals(mSecond,pair.mSecond);
                }
            } else if (mFirst.equals(pair.mFirst)) {
                return Objects.equals(mSecond,pair.mSecond);
            }
            return false;
        } else {
            return false;
        }
    }

    public int hashCode() {
        int result = mFirst != null ? mFirst.hashCode() : 0;
        result = 31 * result + (mSecond != null ? mSecond.hashCode() : 0);
        return result;
    }
}